<?php

namespace App\Component;

use App\Core\Exception\DefaultException;
use App\Core\OutputTrait;

class BaseComponent extends \App\Core\BaseCore{
    
    /**
     * 魔术方法，直接获取getter方法对应的属性项
     * @param $name
     * @return mixed
     * @throws DefaultException
     */
    public function __get($name){
        $getter = 'get' . $name;
        if(method_exists($this, $getter)){
            return $this->$getter();
        }
        
        throw new DefaultException('Getting unknown property: ' . get_class($this) . '::' . $name);
    }
    
    /**
     * 魔术方法，直接设置属性值
     * @param $name
     * @param $value
     * @throws DefaultException
     */
    public function __set($name, $value){
        $setter = 'set' . $name;
        if(method_exists($this, $setter)){
            $this->$setter($value);
        }
        throw new DefaultException('Getting unknown property: ' . get_class($this) . '::' . $name);
    }
}